package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TenderSuppliers;
import com.ruoyi.system.service.ITenderSuppliersService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 供应商信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@Controller
@RequestMapping("/system/suppliers")
public class TenderSuppliersController extends BaseController
{
    private String prefix = "system/suppliers";

    @Autowired
    private ITenderSuppliersService tenderSuppliersService;

    @RequiresPermissions("system:suppliers:view")
    @GetMapping()
    public String suppliers()
    {
        return prefix + "/suppliers";
    }

    /**
     * 查询供应商信息列表
     */
    @RequiresPermissions("system:suppliers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TenderSuppliers tenderSuppliers)
    {
        startPage();
        List<TenderSuppliers> list = tenderSuppliersService.selectTenderSuppliersList(tenderSuppliers);
        return getDataTable(list);
    }

    /**
     * 导出供应商信息列表
     */
    @RequiresPermissions("system:suppliers:export")
    @Log(title = "供应商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TenderSuppliers tenderSuppliers)
    {
        List<TenderSuppliers> list = tenderSuppliersService.selectTenderSuppliersList(tenderSuppliers);
        ExcelUtil<TenderSuppliers> util = new ExcelUtil<TenderSuppliers>(TenderSuppliers.class);
        return util.exportExcel(list, "供应商信息数据");
    }

    /**
     * 新增供应商信息
     */
    @RequiresPermissions("system:suppliers:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商信息
     */
    @RequiresPermissions("system:suppliers:add")
    @Log(title = "供应商信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TenderSuppliers tenderSuppliers)
    {
        return toAjax(tenderSuppliersService.insertTenderSuppliers(tenderSuppliers));
    }

    /**
     * 修改供应商信息
     */
    @RequiresPermissions("system:suppliers:edit")
    @GetMapping("/edit/{supplierId}")
    public String edit(@PathVariable("supplierId") Long supplierId, ModelMap mmap)
    {
        TenderSuppliers tenderSuppliers = tenderSuppliersService.selectTenderSuppliersBySupplierId(supplierId);
        mmap.put("tenderSuppliers", tenderSuppliers);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商信息
     */
    @RequiresPermissions("system:suppliers:edit")
    @Log(title = "供应商信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TenderSuppliers tenderSuppliers)
    {
        return toAjax(tenderSuppliersService.updateTenderSuppliers(tenderSuppliers));
    }

    /**
     * 删除供应商信息
     */
    @RequiresPermissions("system:suppliers:remove")
    @Log(title = "供应商信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tenderSuppliersService.deleteTenderSuppliersBySupplierIds(ids));
    }
}
